package com.csi.controller.user;

import com.alibaba.fastjson2.JSON;
import com.csi.pojo.Result;
import com.csi.service.UserService;
import com.csi.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/user/queryPayPasswordController")
public class QueryPayPasswordController extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        resp.setContentType("application/json;charset=utf-8");
        PrintWriter out = resp.getWriter();

        // 获取请求参数
        String userNumber = req.getParameter("userNumber");

        UserService userService = new UserServiceImpl();
        String payPassword = userService.queryPayPassword(userNumber);

        Result result = new Result<>();
        if (payPassword != null) {
            result.setCode(200);
            result.setMsg("查询成功");
            result.setDatas(payPassword);
        } else {
            result.setCode(500);
            result.setMsg("查询失败，用户不存在或未设置支付密码");
        }
        out.print(JSON.toJSONString(result));

    }
}
